import {TreeNode} from "./Tree.mjs";

function isSymmetric(root: TreeNode | null): boolean {
    if(root == null) return true
    if(root.left?.val != root.right?.val) return false
    const check =(left: TreeNode | null, right:TreeNode | null): boolean => {
        if(!left && !right) return true
        if(!left|| !right) return false
        return left.val === right.val && check(left.left,right.right) && check(left.right,right.left)
    }
    return check(root.left,root.right)
};

console.log(isSymmetric(new TreeNode(1,new TreeNode(2),new TreeNode(2))));